<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="common :: header('WeiAdmin')"/>
    <link href="/admin/css/loader.css" rel="stylesheet"/>
    <link href="/admin/css/admin.css" rel="stylesheet"/>
</head>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" lay-filter="settingForm" action="" onsubmit="return false">
            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                <ul class="layui-tab-title">
                    <li class="layui-this">短信设置</li>
                </ul>
                <div class="layui-tab-content">
                    <div class="layui-form-item">
                        <label class="layui-form-label">短信类型</label>
                        <div>
                            <input checked name="sms_type" class="layui-radio" lay-filter="type-radio-filter" title="阿里云短信"
                                   type="radio" value="1" th:checked="${info.sms_type eq '1'}">
                            <input name="sms_type" title="腾讯云短信" class="layui-radio" lay-filter="type-radio-filter"  type="radio"
                                   value="2" th:checked="${info.sms_type eq '2'}">
                        </div>
                    </div>
                    <div id="tab1" th:class="${info.sms_type=='1'} ? 'layui-tab-item layui-show':'layui-tab-item' ">
                        <div class="layui-form-item">
                            <label class="layui-form-label">accessKeyId</label>
                            <div class="layui-input-inline">
                                <input type="text" name="ali_accessKeyId"  placeholder="请输入accessKeyId" autocomplete="off" class="layui-input" th:value="${info.ali_accessKeyId}">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">accessKeySecret</label>
                            <div class="layui-input-inline">
                                <input type="text" name="ali_accessKeySecret"  placeholder="请输入accessKeySecret" autocomplete="off" class="layui-input" th:value="${info.ali_accessKeySecret}">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">短信签名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="ali_signName"  placeholder="请输入短信签名" autocomplete="off" class="layui-input" th:value="${info.ali_signName}">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">短信模板CODE</label>
                            <div class="layui-input-inline">
                                <input type="text" name="ali_templateCode"  placeholder="请输入短信模板CODE" autocomplete="off" class="layui-input" th:value="${info.ali_templateCode}">
                            </div>
                        </div>
                        <input type="hidden" name="ali_codeKey" value="code" placeholder="请输入短信验证码模板变量" autocomplete="off" class="layui-input" th:value="${info.ali_codeKey}">

                        <div class="layui-form-item">
                            <label class="layui-form-label">短信验证码有效期(分钟)</label>
                            <div class="layui-input-inline">
                                <input type="number" name="ali_expire_minute" value="30" placeholder="请输入短信验证码有效期" autocomplete="off" class="layui-input" th:value="${info.ali_expire_minute}">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="pear-btn pear-btn-primary" lay-submit lay-filter="formDemo">保存</button>
                            </div>
                        </div>
                    </div>
                    <div id="tab2" th:class="${info.sms_type=='2'} ? 'layui-tab-item layui-show':'layui-tab-item' ">
                        <div class="layui-form-item">
                            <label class="layui-form-label">应用accessKeyId</label>
                            <div class="layui-input-inline">
                                <input type="text" name="tecent_accessKeyId"  placeholder="请输入accessKeyId" autocomplete="off" class="layui-input" th:value="${info.tecent_accessKeyId}">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">密钥accessKeySecret</label>
                            <div class="layui-input-inline">
                                <input type="text" name="tecent_accessKeySecret"  placeholder="请输入accessKeySecret" autocomplete="off" class="layui-input" th:value="${info.tecent_accessKeySecret}">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">短信签名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="tecent_signName"  placeholder="请输入短信签名" autocomplete="off" class="layui-input" th:value="${info.tecent_signName}">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">短信模板ID</label>
                            <div class="layui-input-inline">
                                <input type="text" name="tecent_templateID"  placeholder="请输入短信模板CODE" autocomplete="off" class="layui-input" th:value="${info.tecent_templateID}">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">短信应用ID</label>
                            <div class="layui-input-inline">
                                <input type="text" name="tecent_appIDSdk" value="code" placeholder="请输入短信应用ID" autocomplete="off" class="layui-input" th:value="${info.tecent_appIDSdk}">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="pear-btn pear-btn-primary" lay-submit lay-filter="formDemo">保存</button>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </form>
    </div>
</div>
</div>
<th:block th:include="common :: footer"/>
<script>
    layui.use(['form','laydate','jquery','upload'], function(){
      var form = layui.form;
      let $ = layui.jquery;
        form.on('radio(type-radio-filter)', function(data){
          let value = data.elem.value;
          let tabid = "#tab" +  value;
          $(".layui-tab-item").hide();
          $(".layui-tab-item").removeClass("layui-show");
          $(tabid).show();
      })

      form.on('submit(formDemo)', function(data){
          debugger;
          $.ajax({
                url: '/admin/plugin/updateSms',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function (result) {
                    if (result.code) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            //parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            //parent.layui.table.reload("role-table");
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                    }
                }
            })
          return false;
      });
    });
</script>
</body>
</html>